/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package its.serviceSystem.Bean;

import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import mx.its.dds2.ServicesSystem.Modelo.Profile;
import mx.its.dds2.serviceSystem.Bl.ProfileBlLocal;

/**
 *
 * @author Carlos Asis
 */
@ManagedBean
@SessionScoped
public class ProfileBean {

    @EJB
    private ProfileBlLocal profileBl;

    
    private Profile profile;
    private List<Profile>  listProfiles;
    private int b=0;
    
    public ProfileBean() {
        profile=new Profile();
    }

    public Profile getProfile() {
        return profile;
    }

    public void setProfile(Profile profile) {
        this.profile = profile;
    }

    public List<Profile> getProfiles() {
        listProfiles=profileBl.getListAll();
        return listProfiles;
    }

    public void setProfiles(List<Profile> listProfiles) {
        this.listProfiles = listProfiles;
    }
    
  
    
    public String prepararNuevo(){
        b=1;
        profile = new Profile();
        return "ProfileCreateEdit";
    }
    
    public void prepararEditar(ActionEvent a){
        b=2;
        String cId=a.getComponent().getClientId().split(":")[2];
        int id= Integer.parseInt(cId);
        profile=listProfiles.get(id);
    }
    
    public String guardar(){
        switch (b) {
            case 1:
                profileBl.register(profile);
                break;
            case 2:
                profileBl.modify(profile);
                break;
            case 3:
               // profileBl.r(profile);
        }
        return "ProfileFacelets";
    }
    
    public void eliminar(ActionEvent a){
        b=3;
        String cId = a.getComponent().getClientId().split(":")[2];
        int id = Integer.parseInt(cId);
        profile = listProfiles.get(id);
        guardar();
    }
}
